From time to time, you may need to create custom subtypes in order to fully access the powerful, customisable API that SciChart.js has to offer.
The PaletteProvider API is one example where you may have to provide your own implementation of an interface to a SciChart series. If you want your custom paletteProvider to be serialised and deserialised, you need to implement toJSON on it.
Here is an example below:
Once you have created your custom type and implemented toJSON(), next you will need to register the type with the builder API to be able to use it.
Example Title |
Copy Code
|
---|---|
import { chartBuilder } from "scichart/Builder/chartBuilder"; // Register it for use by the builder api chartBuilder.registerType( EBaseType.PaletteProvider, "ExampleMountainPaletteProvider", (options) => new ExampleMountainPaletteProvider(options) ); |
Now the usage of the custom type can be done as follows. It will appear to the Builder API as just another type like those already existing in SciChart.
Example Title |
Copy Code
|
---|---|
import { chartBuilder } from "scichart/Builder/chartBuilder"; // Build the surface const { sciChartSurface, wasmContext } = await chartBuilder.build2DChart(divElementId, { series: { type: ESeriesType.MountainSeries, options: { // Specify the custom palette provider which was previously registered paletteProvider: { type: EPaletteProviderType.Custom, customType: "ExampleMountainPaletteProvider", options: { stroke: "lime", fill: "yellow" } }, } } }); |
Custom Types Example
For a full example of how to use Custom Types with the Builder API, see the SciChart.js demo https://demo.scichart.com/javascript-custom-types.